home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000115_icon-group-sender _Mon Dec 13 08:31:53 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  4KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 14 Dec 1993 18:01:36 MST
  2. Date: 13 Dec 93 08:31:53 GMT
  3. From: csus.edu!netcom.com!rfg@decwrl.dec.com  (Ronald F. Guilmette)
  4. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  5. Subject: Need help with (simple?) programming problem.
  6. Message-Id: <rfgCHyt15.Fpz@netcom.com>
  7. Sender: icon-group-request@cs.arizona.edu
  8. To: icon-group@cs.arizona.edu
  9. Status: RO
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. My thanks to to the several people who replied to my earlier request for
  13. general information about the nature of ICON.
  14.  
  15. I have obtained Griswold's 2nd Edition book, and (believe it or not) I
  16. already plowed most of the way through it (although I confess that I only
  17. skimmed most of the parts relating to string scanning).  The book is well
  18. written, which I appreciate greatly.
  19.  
  20. Naturally, as with every language I've ever studied, there are a few minor
  21. things I might change (adding enum types for example) but I'll save those
  22. comments for another message (to be posted someday after I feel like I've
  23. reached at least the ICON brown-belt level).
  24.  
  25. Anyway, today I need/want to solve a real problem, and I'm hoping one or
  26. more of you ICON gurus will lend me a hand.
  27.  
  28. In a nutshell, here's what I want to do...
  29.  
  30. Assume that I have three strings, i.e. "red ", "green ", and "blue ". Now
  31. I want to create a generator which will successively yield each unique
  32. string which contains no more than one instance of each of the original
  33. strings.  Here are the string values which should be yielded by the various
  34. invocations/resumptions of the generator:
  35.  
  36.         ""
  37.         "red "
  38.         "green "
  39.         "blue "
  40.         "red green "
  41.         "red blue "
  42.         "green red "
  43.         "green blue "
  44.         "blue red "
  45.         "blue green "
  46.         "red green blue "
  47.         "red blue green "
  48.         "green red blue "
  49.         "green blue red "
  50.         "blue red green "
  51.         "blue green red "
  52.  
  53. After being invoked/resumed 16 times (and yielding each of the above strings
  54. once) the generator should fail.  Note that the actual *order* in which the
  55. above strings are yielded is totally unimportant.  Any order will do as long
  56. as I get these 16 strings (eventually).
  57.  
  58. Also note that the ORDER in which the original strings appear in the genera-
  59. ted strings *is* significant.
  60.  
  61. This is just an example of the kind of thing I want to learn how to do.
  62.  
  63. Basically, I'm hoping that someone will be able to show me some GENERAL
  64. techinque for creating a generator along these lines.  (In practice, for
  65. my *real* problem, the number of original strings will in fact be larger
  66. than three... but it *will* be a fixed number (probably less that 12).
  67.  
  68. Is there a simple solution and/or well-known idiom for this general class
  69. of problems in ICON?  If so, some example code would be most enlightening.
  70.  
  71. P.S.  It probably makes no difference, but in the case of my *real* problem,
  72. one or more of the "original strings" may not actually be strings at all.
  73. They may instead be generators which produce various strings.  But the
  74. rules of the game will remain essentially the same, i.e. the strings
  75. yielded by my new generator must never contain any more than one instance
  76. of any one of the "inputs" (where an "input" could be either a literal
  77. string, or any one of the strings yielded by a given "input generator".
  78. For example:
  79.  
  80.         procedure greenish_input_generator ()
  81.             suspend "green " | "light-green "
  82.         end
  83.  
  84. I never want to see any more than one greenish color in the strings yielded
  85. by my new generator.
  86.  
  87. -- 
  88.  
  89. -- Ronald F. Guilmette, Sunnyvale, California -------------------------------
  90. ------ domain address: rfg@netcom.com ---------------------------------------
  91. ------ uucp address: ...!uunet!netcom.com!rfg -------------------------------
  92.